<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>awd</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background: gold;
            position: fixed;
            top: 100px;
            left: 0px;
        }

    </style>

    <script>
        window.onload = function () {
            var oBox = document.getElementById('box');

            var iLeft = 0;

            var timer = setInterval(move, 30);
            var flag = 0;

            function move() {
                if (iLeft > 600) {
                    flag = 1
                }

                if (iLeft <= 0) {
                    flag = 0
                }

                if (flag === 0) {
                    iLeft += 10;
                } else if (flag === 1) {
                    iLeft -= 10;
                }


                oBox.style.left = iLeft + 'px';
            }


        }
    </script>

</head>
<body>
<div class="box" id="box"></div>
</body>
</html>